package com.imooc.user.controller;

import com.imooc.api.controller.user.HelloControllerApi;
import com.imooc.grace.result.GraceJSONResult;
import com.imooc.user.mapper.AppUserMapper;
import com.imooc.utils.RedisOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: bie
 * @create: 2021-06-30 08:08
 */
@RestController
@Slf4j
public class HelloController implements HelloControllerApi {

    @Resource
    private AppUserMapper appUserMapper;

    @Autowired
    private RedisOperator redisOperator;

    public Object hello() {
        log.debug("debug");
        log.info("info");
        log.warn("warn");
        log.error("error");
        // return "hello";
        // 之前封装结果集的方式
        // return IMOOCJSONResult.ok();
        // return IMOOCJSONResult.ok("hello");
        // return IMOOCJSONResult.errorMsg("您的信息有误");

        // 本次教程优化方式:  更优雅的封装结果集方式
        // 定义枚举  ResponseStatusEnum
        // 然后封装结果集 GraceJSONResult 时传入对应枚举
        // return GraceJSONResult.ok();
        // return GraceJSONResult.errorTicket();
        // return GraceJSONResult.errorCustom(ResponseStatusEnum.NO_AUTH);

        // 测试整合mybatis
        return GraceJSONResult.ok(appUserMapper.selectAll());

    }

    @GetMapping("/redis")
    public Object redis(){
        redisOperator.set("age","18");
        return GraceJSONResult.ok(redisOperator.get("age"));
    }

}
